home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group99a.txt
/
000056_icon-group-sender _Tue Mar 23 09:20:56 1999.msg
< prev
next >
Wrap
Internet Message Format
|
2000-09-20
|
2KB
Return-Path: <icon-group-sender>
Received: (from root@localhost)
by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) id JAA28013
for icon-group-addresses; Tue, 23 Mar 1999 09:20:49 -0700 (MST)
Message-Id: <199903231620.JAA28013@baskerville.CS.Arizona.EDU>
To: icon-group@optima.CS.Arizona.EDU
Date: Tue, 23 Mar 1999 08:54:14 -0500
From: Robert Wyesham <rwyesham@earthlink.net>
Subject: Help for the Newbie!
Errors-To: icon-group-errors@optima.CS.Arizona.EDU
Status: RO
I'd like to define an "assert" macro for use in my Icon programs, using ipp, of
course.
I need criticism and advice regarding the definition that I'm proposing.
I decided to steal from the best, so I looked up the definition that P.J.
Plauger used in his book, "The Standard C Library." Here it is, with
line-numbering added, in order to make it easy to refer to (any mistakes are my
own):
1. #undef assert
2. #ifdef NDEBUG
3. #define assert(test) ((void)0)
4. #else
5. #define _STR(x) _VAL(x)
6. #define _VAL(x) #x
7. #define assert(test) (test) ? (void)0 : \
8. _Assert( __FILE__ ":" _STR(__LINE__) #test )
9. #endif
The _STR and _VAL macros turn the __LINE__ macro from an integer into a string.
Dr. Plauger defined assert as a ternary expression, rather than as an 'if'
statement, so that crazy people could use the comma operator to do deranged
things like:
( assert(0 < x), x < y )
Without an assert macro, I've been writing:
$ifndef NDEBUG
if test then
(&null)
else
stop( "--- assertion failed: file ", &file, ", line ", &line )
$endif
I'm proposing this:
10. $undef assert
11. $ifdef NDEBUG
12. $define assert(test) (&null)
13. $else
14. $define assert(test) if test then (&null) else \
15. stop( "--- assertion failed: file ", &file,
", line ", &line )
16. $endif
Does anyone see anything basically wrong with this definition? Are there
mistakes in it?
Are there better ways to do this? A big problem with it is that the test never
gets printed.
I have no idea how to turn the test into a string that I can print. ipp and Icon
must have a way to do this, but I haven't thought of it. Of course, in a macro,
everything's a string. At this point, I get confused. Any ideas?
Thanks and best regards,
- rob
Rob Wyesham,
Wilmington, Delaware